<?php

if ( !class_exists( "BME_dataset" ) ) {
require_once("Object.php");

class BME_dataset extends BME_object {
	
	var $name;	// str	Name.
	var $shortName;	// str	Short Name.
	var $contact;	// str	Who.
	var $comments;	// str	Comments.

	/**
	 * bme_dataset new bme_dataset([mix id[, int version]]);
	 * @param mix id (optional): The ID on Lcl-DB (int), or the ID.version (str or float).
	 * @param int version (optional): The version of the sequence.
	 * @return bme_dataset (object).
	 */
	function BME_dataset($id=NULL,$version=NULL) {
		parent::__construct($id,$version);
	}
	/**
	 * bool load(int id[, int version]);
	 * @param int id.
	 * @param int version (optional): Last version by default.
	 * @return bool: success.
	 */
	function load($id,$version=NULL){
		$this->_parseId($id,$version);
		$out=false;
		$ver="";
		if(is_int($version)) $ver=" AND `version`='$version'";
		$this->openDB();
		$res=$this->DBquery("select * from `Dataset` where `idDataset`='$id' $ver ORDER BY `version` DESC");
		if($row=$this->DBfetch_assoc($res)){
			$this->id = (int)$row["idDataset"];
			$this->version = (int)$row["version"];
			$this->source = $row["source"];
			$this->name = $row["name"];
			$this->shortName = $row["shortName"];
			$this->contact = $row["contact"];
			$this->comments = $row["comments"];
			$out=true;
		}
		$this->closeDB();
		return $out;
	}
	/**
	 * str getname(void);
	 * @return str: Name.
	 */
	function getName(){
		assert('isset($this->id)');
		return (string)$this->name;
	}
	/**
	 * str getshortname(void);
	 * @return str: Short Name.
	 */
	function getShortName(){
		assert('isset($this->id)');
		return (string)$this->shortName;
	}
	/**
	 * str getcontact(void);
	 * @return str: Who.
	 */
	function getContact(){
		assert('isset($this->id)');
		return (string)$this->contact;
	}
	/**
	 * str getcomments(void);
	 * @return str: Comments.
	 */
	function getComments(){
		assert('isset($this->id)');
		return (string)$this->comments;
	}
	/**
	 * arr getseqsid([int from[, int number]]);
	 * @param int from: The initial row to return, 0 by default.
	 * @param int number: The number of IDs to return, all after $from by default.
	 * @return arr: Array of Int, IDs of sequences on the dataset.
	 */
	function getSeqsId($from=0,$number=NULL){
		if(is_null($number)) $number=$this->countSeqs();
		$out=array();
		$this->openDB();
		$res=$this->DBquery("select `idSequence` from `Sequence` where `Dataset_idDataset`='".$this->getId()."' limit $from,$number");
		while($row=$this->DBfetch_assoc($res)) $out[]=(int)$row["idSequence"];
		$this->closeDB();
		return $out;
	}
	/**
	 * int countseqs(void);
	 * @return int: Number of sequences on the dataset.
	 */
	function countSeqs(){
		$this->openDB();
		$res=$this->DBquery("select count(*) as count from `Sequence` where `Dataset_idDataset`='".$this->getId()."'");
		$row=$this->DBfetch_assoc($res);
		$this->closeDB();
		return (int)$row["count"];
	}
	/**
	 * arr getall(void);
	 * @return arr: Arr of int, array of IDs.
	 */
	function getAll(){
		$out=array();
		$this->openDB();
		$res=$this->DBquery("select `idDataset` from `Dataset`");
		while($row=$this->DBfetch_assoc($res)){
			$out[]=(int)$row["idDataset"];
		}
		$this->closeDB();
		return $out;
	}
}

}


?>
